<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    table{
        border-collapse: collapse;
    }
    table th{
        border: 1px solid black;
        line-height: 50px;
        padding: 0 30px;  
    }
    table td{
        border: 1px solid black;
        line-height: 50px;
        padding: 0 24px;  
        text-align: center;
    }
    
</style>
<body>
    <button id="btn">添加一条新的访客信息</button>
    <table>
        <tr>
            <th>序列号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>操作</th>
        </tr>
    </table>
    <script>
        var info = [{
            name: "胡杭",
            age: 16
        }, {
            name: "胜明",
            age: 22
        }, {
            name: "军毅",
            age: 21
        }, {
            name: "晓华",
            age: 13
        }, {
            name: "盛聪",
            age: 23
        }, {
            name: "侦剑",
            age: 32
        }, {
            name: "红翔",
            age: 25
        }, {
            name: "超维",
            age: 18
        }, {
            name: "士琪",
            age: 22
        }, {
            name: "艳华",
            age: 20
        }];
        
        let btn = document.querySelector("#btn");
        let del = document.querySelector("#del");
        table = document.querySelector("table");

        index = 0;
        btn.onclick = function(){
            table.innerHTML = table.innerHTML+"<tr><td>" + (index + 1) + "</td><td>"+ info[index].name +"</td><td>" + info[index].age+"</td><td><button id='del' >删除</button></td></tr>";
            index++;
            // console.log(btn);  控制台测试

            
        };
        table.onclick=function(index){
                if(index.target.nodeName == "BUTTON"){
                    index.target.parentNode.parentNode.remove();
                }
                
            }
        
    </script>
</body>
</html>